00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <iostream>
00021 #include <iterator>
00022 #include <boost/mpi.hpp>
00023 #include <boost/mpi/collectives.hpp>
00024
00025 #ifndef _printit_hpp_
00026 #define _printit_hpp_
00027
00028
00029
00030
00031 template <typename T>
00032 void
00033 printit(const boost::mpi::communicator& comm,
00034 const std::vector<T> things,
00035 const std::string& caption)
00036 {
00037 if (!caption.empty() && comm.rank() == 0) {
00038 std::cout << caption << std::endl;
00039 std::cout.flush();
00040 }
00041 for (int p = 0; p < comm.size(); ++p) {
00042 if (comm.rank() == p) {
00043 std::cout << p << ": ";
00044 std::copy(things.begin(), things.end(),
00045 std::ostream_iterator<T>(std::cout, ","));
00046 std::cout << std::endl;
00047 std::cout.flush();
00048 }
00049 comm.barrier();
00050 }
00051
00052 size_t global_size;
00053 boost::mpi::reduce(comm, things.size(), global_size, std::plus<size_t>(), 0);
00054 if (comm.rank() == 0) {
00055 if (!caption.empty()) {
00056 std::cout << caption;
00057 }
00058 std::cout << "Number of things: " << global_size << std::endl;
00059 }
00060 }
00061
00062
00063
00064 #endif